package com.hw.hcit.feature;

import java.util.ArrayList;
import java.util.List;

import android.os.RemoteException;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.android.internal.statusbar.IStatusBarService;
import com.hw.hcit.R;
import com.hw.hcit.conf.Config;
import com.hw.hcit.conf.JCtrlCallback;
import com.hw.hcit.conf.JTestItem;
import android.os.ServiceManager;
public class ProjectsTest extends JTestItem implements OnItemClickListener 
{
	private String TAG = "ProjectsTest";
	private ListView mlisListView;
	
	
	final Object mServiceAquireLock = new Object();
	IStatusBarService mStatusBarService;
	public ProjectsTest() {
		super();
	}
	
	public ProjectsTest(JCtrlCallback cb) {
		super(cb);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
	{
			View rootView = inflater.inflate(R.layout.projects, container, false);
			
			mlisListView = (ListView) rootView.findViewById(R.id.test_list);
			
			mlisListView.setAdapter(new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, getData()));
			
			mlisListView.setOnItemClickListener(this);
			
			return rootView;
	}

	/*15-10-26 gaoshenpan fix show navigation after NV saved in AutoResultTest begin*/
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.d(TAG, "onclick--------->replace");
		showNavigationBar();
	}
	/*15-10-26 gaoshenpan fix show navigation after NV saved in AutoResultTest end*/
	@Override
	public boolean getResult() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String getResultInfo() {
		// TODO Auto-generated method stub
		return ret;
	}

	@Override
	public void startTest() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void stopTest() {
		// TODO Auto-generated method stub
		
	}
	
	public void refresh()
	{
		
	}

	String ret = "";
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		ret = String.valueOf(arg2);
		this.testFinish(true);
	}
	
	@Override
	public List<String> getData() {
		List<String> data = new ArrayList<String>();
		
		int c = Config.PROJECTS.getSize();
		String s = "";
		Log.d(TAG, "c = --------->"+c );
		for(int i=0;i<c;i++)
		{
			data.add(Config.PROJECTS.getValue(i).getName());
			Log.d(TAG, "getName() --------->"+Config.PROJECTS.getValue(i).getName() );
		}
	         
	        return data;
	}
	
	/*15-10-26 gaoshenpan fix show navigation after NV saved in AutoResultTest begin*/
	private void showNavigationBar() {
		/*try {
			Log.d(TAG, " --------->showNavigationBar()");
			IStatusBarService statusbar = getStatusBarService();
			if (statusbar != null) {
				statusbar.showNavigationBar();
			}
		} catch (RemoteException e) {
			// re-acquire status bar service next time it is needed.
			mStatusBarService = null;
		}*/

	}
	
	IStatusBarService getStatusBarService() {
        synchronized (mServiceAquireLock) {
            if (mStatusBarService == null) {
                mStatusBarService = IStatusBarService.Stub.asInterface(
                        ServiceManager.getService("statusbar"));
            }
        }
        /*15-11-21 gaoshenpan fix mStatusBarService locked begin*/
        return mStatusBarService;
        /*15-11-21 gaoshenpan fix mStatusBarService locked end*/
    }
	/*15-10-26 gaoshenpan fix show navigation after NV saved in AutoResultTest end*/
}
